package controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import pojo.Orderlist;
import service.AdminOrderService;
import service.OrderService;

import java.util.List;

@Controller
public class AdminOrder {
    @Autowired
    private AdminOrderService adminOrderService;
    @Autowired
    private OrderService orderService;
    @RequestMapping("/initDeO")
    public String initDeO(Model model){
        List<Orderlist> orderlists=adminOrderService.sAOL();
        model.addAttribute("orderlist",orderlists);
        return "adminDeleteOneOrderListPage";}
    @RequestMapping("/deleteOrder")
    public String deleteOrder(Integer oid, Model model){
        List<Orderlist> orderlists=adminOrderService.sAOL();
        int a= adminOrderService.dOL(oid);
        if (a>0){
            List<Orderlist> orderlist=adminOrderService.sAOL();
            model.addAttribute("orderlist",orderlist);
            model.addAttribute("msg","删除成功！");
            return "adminDeleteOneOrderListPage";
        }
        model.addAttribute("orderlist",orderlists);
        model.addAttribute("msg","删除失败！");
        return "adminDeleteOneOrderListPage";
    }
    @RequestMapping("/toSelect")
    public String initSelect(){return "adminSelectOneOrderListPage";}
    @RequestMapping("/selectOneOrder")
    public String selectOneOrder(Integer oid,Model model){
        List<Orderlist> orderlist=adminOrderService.sOOL(oid);
        if (orderlist.size()!=0){
            model.addAttribute("orderlist",orderlist);
            return "adminSelectOneOrderListPage";
        }
        model.addAttribute("msg","找不到该订单！");
        return "adminSelectOneOrderListPage";
    }
    @RequestMapping("/selectAllOrder")
    public String selectAllOrder(Model model){
        List<Orderlist> orderlist=adminOrderService.sAOL();
        model.addAttribute("orderlist",orderlist);
        return "adminSelectAllOrderListPage";
    }
    @RequestMapping("/initChange")
    public String initChange(Model model){
        List<Orderlist> orderlist=adminOrderService.sAOL();
        model.addAttribute("orderlist",orderlist);
        return "adminChangeOrderListState";
    }
    @RequestMapping("/toChangeState")
    public String toChange(Integer oid,Model model){
        int a= orderService.deal(oid);
        if (a>0){
            System.out.println("修改订单状态成功！");
            List<Orderlist> orderlist=adminOrderService.sAOL();
            model.addAttribute("orderlist",orderlist);
            model.addAttribute("msg","修改订单状态成功");
            return "adminChangeOrderListState";
        }
        System.out.println("修改订单状态失败！");
        return "adminChangeOrderListState";
    }
}
